from utils import find_element, handle_conf
from selenium.webdriver.common.by import By
section = 'search'


class Search:
    def __init__(self):
        self.conf = handle_conf.HandleConf(handle_conf.HandleConf('conf.ini').get_value('data', 'data_name'))
        self.driver = find_element.FindElement(self.conf.get_value('search', 'url'))

    def get_input_object(self):
        """
        获取输入框对象
        """
        method = self.conf.get_value(section, 'search_input_method')
        element = self.conf.get_value(section, 'search_input_element')
        return self.driver.find_element(method, element)

    def get_button_object(self):
        """
        获取按钮对象
        """
        method = self.conf.get_value(section, 'search_button_method')
        element = self.conf.get_value(section, 'search_button_element')
        return self.driver.find_element(method, element)

    def input_value(self, value):
        """
        输入搜索内容
        """
        return self.get_input_object().send_keys(value)

    def click_button(self):
        """
        点击按钮
        """
        return self.get_button_object().click()

    def assert_case_01(self):
        """
        01用例断言
        """
        method = self.conf.get_value(section, 'case01_method')
        element = self.conf.get_value(section, 'case01_element')
        actual_text = self.driver.find_element(method, element).text
        expected_result = self.conf.get_value(section, 'case01_expected')
        return actual_text, expected_result

# search = Search()
# search.input_value('selenium')